package com.baizhi.controller;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class UserController {
    @Autowired
    private UserService service;
    @PostMapping("useres")
    public String login(@RequestBody User user, HttpSession httpSession){
        String realCode = (String) httpSession.getAttribute("code");
        boolean b = service.selectByEmail(user,httpSession);
        if(user.getCode().equalsIgnoreCase(realCode)){
            if(service.selectByEmail(user,httpSession)){
                return "true";
            }
            return "userFalse";
        }return "error";
    }
    @DeleteMapping("useres")
    public void goOut(HttpSession session){
        session.removeAttribute("user");
    }
}
